package com.note.simpleadmin.module.authc.controller;

import com.note.simpleadmin.module.authc.service.BgUserService;
import com.note.simpleadmin.constant.ErrorCode;
import com.note.simpleadmin.exception.DataUnanimousException;
import com.note.simpleadmin.utils.UserUtil;
import com.note.simpleadmin.vo.Msg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/***
 *@ClaseName:PassController
 *
 *@Decription:
 *
 *@Author: xubingbing
 *
 *@Date:2019/1/28 0028 20:47
 */
@Controller
@RequestMapping(value = "pass")
public class PassController {
    private final static Logger logger = LoggerFactory.getLogger(PassController.class);
    @Autowired
    private BgUserService bgUserService;
    @RequestMapping(value = "ajax_update")
    @ResponseBody
    public Msg ajax_update(String oldpassword,String newpassword) {
        Msg msg=new Msg();
        try {
            msg.setErrorCode(ErrorCode.ERROR_OK);
            bgUserService.updatePassword(UserUtil.getUserId(),oldpassword,newpassword);
            msg.setMsg("修改成功");
        } catch(DataUnanimousException e) {
            msg.setMsg(e.getMessage());
            msg.setErrorCode(ErrorCode.ERROR_1000);
        }
        catch (Exception e) {
            logger.error(e.getMessage());
            msg.setMsg("系统异常");
            msg.setErrorCode(ErrorCode.ERROR_1001);
        }
        return msg;
    }
    @RequestMapping(value = "passUI")
    public String passUI()
    {
        return "pass";
    }
}
